package servlet.manage.nav;

import dto.NavModelDto;
import service.INavService;
import service.impl.NavServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/NavAdd")
public class NavAddServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String href =req.getParameter("href");
        String title =req.getParameter("title");

        NavModelDto navModelDto =new NavModelDto();
        navModelDto.setHref(href);
        navModelDto.setTitle(title);
        INavService nav =new NavServiceImpl();
        int num= nav.add(navModelDto);//代表影响的数据条数,如果是1则成功，其他则失败

        //页面转发
//        req.getRequestDispatcher("back/navSelect.jsp").forward(req,resp);
//        resp.sendRedirect("/back/NavSelect.jsp");
        resp.getWriter().println(num);//将导航增加结果返回给页面
    }
}
